<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>快乐数字王国 - 幼儿园数字游戏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Comic Sans MS', 'Marker Felt', 'Arial Rounded MT Bold', sans-serif;
            background: linear-gradient(135deg, #FFE4E6 0%, #E6F3FF 50%, #E8F5E8 100%);
            min-height: 100vh;
            overflow-x: hidden;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
            animation: bounce 2s infinite;
        }

        .title {
            font-size: 3rem;
            color: #FF6B6B;
            text-shadow: 3px 3px 0px #FFB6C1;
            margin-bottom: 10px;
        }

        .subtitle {
            font-size: 1.5rem;
            color: #4ECDC4;
            margin-bottom: 20px;
        }

        .game-area {
            background: white;
            border-radius: 30px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            margin-bottom: 20px;
            position: relative;
            overflow: hidden;
        }

        .game-area::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: repeating-linear-gradient(
                45deg,
                transparent,
                transparent 10px,
                rgba(255,255,255,0.1) 10px,
                rgba(255,255,255,0.1) 20px
            );
            animation: float 20s linear infinite;
        }

        .game-modes {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .game-card {
            background: linear-gradient(135deg, #FF9A9E 0%, #FECFEF 100%);
            border-radius: 25px;
            padding: 30px;
            text-align: center;
            cursor: pointer;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .game-card:hover {
            transform: translateY(-10px) scale(1.05);
            box-shadow: 0 15px 40px rgba(0,0,0,0.2);
        }

        .game-card h3 {
            font-size: 1.8rem;
            color: white;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }

        .game-card p {
            font-size: 1.1rem;
            color: white;
            opacity: 0.9;
        }

        .game-card::after {
            content: '🌟';
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 2rem;
            animation: twinkle 1.5s infinite;
        }

        .number-grid {
            display: grid;
            grid-template-columns: repeat(10, 1fr);
            gap: 10px;
            margin: 20px 0;
        }

        .number-cell {
            aspect-ratio: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            font-weight: bold;
            border-radius: 15px;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .number-cell:hover {
            transform: scale(1.1);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .number-cell.correct {
            background: #4CAF50 !important;
            color: white;
            animation: correctPulse 0.6s ease;
        }

        .number-cell.wrong {
            background: #FF5252 !important;
            color: white;
            animation: shake 0.5s ease;
        }

        .number-cell.highlight {
            background: #FFD700 !important;
            color: #333;
            animation: glow 1s infinite alternate;
        }

        .controls {
            text-align: center;
            margin: 20px 0;
        }

        .btn {
            font-size: 1.3rem;
            padding: 15px 30px;
            margin: 10px;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-family: inherit;
            font-weight: bold;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .btn-success {
            background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
            color: white;
        }

        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0,0,0,0.3);
        }

        .score-board {
            background: linear-gradient(135deg, #FFE66D 0%, #FF6B6B 100%);
            border-radius: 25px;
            padding: 20px;
            text-align: center;
            margin-bottom: 20px;
            color: white;
            font-size: 1.5rem;
            font-weight: bold;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }

        .progress-bar {
            width: 100%;
            height: 20px;
            background: rgba(255,255,255,0.3);
            border-radius: 10px;
            overflow: hidden;
            margin-top: 10px;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #4CAF50, #8BC34A);
            transition: width 0.5s ease;
            border-radius: 10px;
        }

        .celebration {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 1000;
        }

        .star {
            position: absolute;
            font-size: 2rem;
            animation: fall 3s linear forwards;
        }

        .instructions {
            background: #E8F5E8;
            border-radius: 20px;
            padding: 20px;
            margin-bottom: 20px;
            border-left: 5px solid #4CAF50;
        }

        .instructions h4 {
            color: #2E7D32;
            font-size: 1.5rem;
            margin-bottom: 10px;
        }

        .instructions p {
            color: #388E3C;
            font-size: 1.2rem;
            line-height: 1.6;
        }

        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% {
                transform: translateY(0);
            }
            40% {
                transform: translateY(-10px);
            }
            60% {
                transform: translateY(-5px);
            }
        }

        @keyframes twinkle {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.3; }
        }

        @keyframes float {
            0% { transform: translateX(-100%) translateY(-100%) rotate(0deg); }
            100% { transform: translateX(100%) translateY(100%) rotate(360deg); }
        }

        @keyframes correctPulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.2); }
            100% { transform: scale(1); }
        }

        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-5px); }
            75% { transform: translateX(5px); }
        }

        @keyframes glow {
            from { box-shadow: 0 0 10px #FFD700; }
            to { box-shadow: 0 0 20px #FFD700, 0 0 30px #FFD700; }
        }

        @keyframes fall {
            to {
                transform: translateY(100vh) rotate(360deg);
                opacity: 0;
            }
        }

        .animal-friend {
            position: absolute;
            font-size: 3rem;
            animation: float-animal 3s ease-in-out infinite;
        }

        @keyframes float-animal {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-20px); }
        }

        @media (max-width: 768px) {
            .title {
                font-size: 2rem;
            }
            
            .number-grid {
                grid-template-columns: repeat(5, 1fr);
            }
            
            .number-cell {
                font-size: 1.2rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1 class="title">🌈 快乐数字王国 🌈</h1>
            <p class="subtitle">和可爱的小动物一起学习数字吧！</p>
        </div>

        <div class="score-board">
            <div>⭐ 小星星: <span id="score">0</span> 颗</div>
            <div class="progress-bar">
                <div class="progress-fill" id="progress" style="width: 0%"></div>
            </div>
        </div>

        <div class="game-area">
            <div id="game-selection">
                <h2 style="text-align: center; color: #FF6B6B; margin-bottom: 20px;">选择你喜欢的游戏吧！</h2>
                <div class="game-modes">
                    <div class="game-card" onclick="startGame('counting')">
                        <h3>🔢 数数游戏</h3>
                        <p>从1数到100，点击正确的数字</p>
                    </div>
                    <div class="game-card" onclick="startGame('sequence')">
                        <h3>🎯 数字接龙</h3>
                        <p>找出下一个应该出现的数字</p>
                    </div>
                    <div class="game-card" onclick="startGame('pattern')">
                        <h3>🧩 数字规律</h3>
                        <p>发现数字之间的秘密规律</p>
                    </div>
                </div>
            </div>

            <div id="game-instructions" style="display: none;">
                <div class="instructions">
                    <h4 id="instruction-title">游戏说明</h4>
                    <p id="instruction-text">点击开始游戏吧！</p>
                </div>
            </div>

            <div id="game-board" style="display: none;">
                <div class="number-grid" id="number-grid"></div>
            </div>

            <div class="controls">
                <button class="btn btn-primary" onclick="startGame(currentGame)" id="start-btn">开始游戏</button>
                <button class="btn btn-success" onclick="backToMenu()" style="display: none;" id="back-btn">返回菜单</button>
            </div>
        </div>
    </div>

    <div class="celebration" id="celebration"></div>

    <script>
        let currentGame = null;
        let score = 0;
        let currentLevel = 1;
        let gameSequence = [];
        let currentStep = 0;
        let correctCount = 0;

        // 音效系统
        const sounds = {
            correct: new Audio('data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBSuBzvLZiTYIG2m98OScTgwOUarm7blmFgU7k9n1unEiBC13yO/eizEIHWq+8+OWT'),
            wrong: new Audio('data:audio/wav;base64,UklGRuICAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YcACAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBSuBzvLZiTYIG2m98OScTgwOUarm7blmFgU7k9n1unEiBC13yO/eizEIHWq+8+OWT'),
            success: new Audio('data:audio/wav;base64,UklGRuICAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YcACAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBSuBzvLZiTYIG2m98OScTgwOUarm7blmFgU7k9n1unEiBC13yO/eizEIHWq+8+OWT')
        };

        function playSound(type) {
            try {
                sounds[type].currentTime = 0;
                sounds[type].play().catch(() => {});
            } catch (e) {}
        }

        function updateScore(points) {
            score += points;
            document.getElementById('score').textContent = score;
            updateProgress();
        }

        function updateProgress() {
            const progress = Math.min((score / 100) * 100, 100);
            document.getElementById('progress').style.width = progress + '%';
        }

        function createCelebration() {
            const celebration = document.getElementById('celebration');
            const emojis = ['⭐', '🌟', '✨', '🎉', '🎊', '🏆'];
            
            for (let i = 0; i < 20; i++) {
                setTimeout(() => {
                    const star = document.createElement('div');
                    star.className = 'star';
                    star.textContent = emojis[Math.floor(Math.random() * emojis.length)];
                    star.style.left = Math.random() * 100 + '%';
                    star.style.animationDelay = Math.random() * 2 + 's';
                    celebration.appendChild(star);
                    
                    setTimeout(() => star.remove(), 3000);
                }, i * 100);
            }
        }

        function startGame(gameType) {
            currentGame = gameType;
            document.getElementById('game-selection').style.display = 'none';
            document.getElementById('game-instructions').style.display = 'block';
            document.getElementById('game-board').style.display = 'block';
            document.getElementById('start-btn').style.display = 'none';
            document.getElementById('back-btn').style.display = 'inline-block';
            
            switch(gameType) {
                case 'counting':
                    document.getElementById('instruction-title').textContent = '🔢 数数游戏';
                    document.getElementById('instruction-text').textContent = '从1开始，按顺序点击数字。每点对一个数字，你就会得到一颗小星星！';
                    initCountingGame();
                    break;
                case 'sequence':
                    document.getElementById('instruction-title').textContent = '🎯 数字接龙';
                    document.getElementById('instruction-text').textContent = '找出应该出现的下一个数字，点击它！';
                    initSequenceGame();
                    break;
                case 'pattern':
                    document.getElementById('instruction-title').textContent = '🧩 数字规律';
                    document.getElementById('instruction-text').textContent = '发现数字之间的规律，点击符合规律的数字！';
                    initPatternGame();
                    break;
            }
        }

        function initCountingGame() {
            const grid = document.getElementById('number-grid');
            grid.innerHTML = '';
            currentStep = 1;
            
            for (let i = 1; i <= 100; i++) {
                const cell = document.createElement('div');
                cell.className = 'number-cell';
                cell.textContent = i;
                cell.style.background = getRainbowColor(i);
                cell.onclick = () => handleCountingClick(i, cell);
                grid.appendChild(cell);
            }
        }

        function initSequenceGame() {
            const grid = document.getElementById('number-grid');
            grid.innerHTML = '';
            
            gameSequence = [];
            let start = Math.floor(Math.random() * 90) + 1;
            let step = Math.floor(Math.random() * 5) + 1;
            
            for (let i = 0; i < 5; i++) {
                gameSequence.push(start + i * step);
            }
            
            const numbers = [...gameSequence, start + 5 * step, start + 6 * step, start - step].sort(() => Math.random() - 0.5);
            
            numbers.forEach(num => {
                if (num > 0 && num <= 100) {
                    const cell = document.createElement('div');
                    cell.className = 'number-cell';
                    cell.textContent = num;
                    cell.style.background = getRainbowColor(num);
                    cell.onclick = () => handleSequenceClick(num, cell);
                    grid.appendChild(cell);
                }
            });
            
            document.getElementById('instruction-text').textContent = `数字接龙：${gameSequence.join(', ')}, 下一个数字是？`;
        }

        function initPatternGame() {
            const grid = document.getElementById('number-grid');
            grid.innerHTML = '';
            
            const patterns = [
                { type: 'even', numbers: [2,4,6,8,10,12,14,16], description: '找出所有的双数！' },
                { type: 'odd', numbers: [1,3,5,7,9,11,13,15], description: '找出所有的单数！' },
                { type: 'tens', numbers: [10,20,30,40,50,60,70,80], description: '找出所有整十的数字！' },
                { type: 'fives', numbers: [5,10,15,20,25,30,35,40], description: '找出所有5的倍数！' }
            ];
            
            const pattern = patterns[Math.floor(Math.random() * patterns.length)];
            gameSequence = pattern.numbers;
            
            const numbers = [...gameSequence, ...Array(8).fill(0).map(() => Math.floor(Math.random() * 100) + 1)].sort(() => Math.random() - 0.5);
            
            numbers.forEach(num => {
                const cell = document.createElement('div');
                cell.className = 'number-cell';
                cell.textContent = num;
                cell.style.background = getRainbowColor(num);
                cell.onclick = () => handlePatternClick(num, cell);
                grid.appendChild(cell);
            });
            
            document.getElementById('instruction-text').textContent = pattern.description;
        }

        function handleCountingClick(number, cell) {
            if (number === currentStep) {
                cell.classList.add('correct');
                playSound('correct');
                updateScore(1);
                currentStep++;
                
                if (currentStep > 100) {
                    setTimeout(() => {
                        alert('🎉 太棒了！你已经数到100了！你是数字小达人！');
                        createCelebration();
                        backToMenu();
                    }, 500);
                }
            } else {
                cell.classList.add('wrong');
                playSound('wrong');
                setTimeout(() => cell.classList.remove('wrong'), 500);
            }
        }

        function handleSequenceClick(number, cell) {
            const correctAnswer = gameSequence[gameSequence.length - 1] + (gameSequence[1] - gameSequence[0]);
            if (number === correctAnswer) {
                cell.classList.add('correct');
                playSound('correct');
                updateScore(5);
                createCelebration();
                setTimeout(() => initSequenceGame(), 1000);
            } else {
                cell.classList.add('wrong');
                playSound('wrong');
                setTimeout(() => cell.classList.remove('wrong'), 500);
            }
        }

        function handlePatternClick(number, cell) {
            if (gameSequence.includes(number)) {
                cell.classList.add('correct');
                playSound('correct');
                updateScore(2);
                correctCount++;
                
                if (correctCount === gameSequence.length) {
                    setTimeout(() => {
                        alert('🎉 太棒了！你发现了数字的规律！');
                        createCelebration();
                        initPatternGame();
                    }, 500);
                }
            } else {
                cell.classList.add('wrong');
                playSound('wrong');
                setTimeout(() => cell.classList.remove('wrong'), 500);
            }
        }

        function getRainbowColor(number) {
            const colors = [
                '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FECA57',
                '#FF9FF3', '#54A0FF', '#5F27CD', '#00D2D3', '#FF9F43'
            ];
            return colors[(number - 1) % colors.length];
        }

        function backToMenu() {
            document.getElementById('game-selection').style.display = 'block';
            document.getElementById('game-instructions').style.display = 'none';
            document.getElementById('game-board').style.display = 'none';
            document.getElementById('start-btn').style.display = 'inline-block';
            document.getElementById('back-btn').style.display = 'none';
            currentGame = null;
            correctCount = 0;
        }

        // 添加可爱的动物朋友
        function addAnimalFriends() {
            const animals = ['🐰', '🐻', '🐨', '🦁', '🐸', '🦄', '🦋', '🐝'];
            const container = document.querySelector('.container');
            
            animals.forEach((animal, index) => {
                const friend = document.createElement('div');
                friend.className = 'animal-friend';
                friend.textContent = animal;
                friend.style.left = (10 + index * 12) + '%';
                friend.style.top = (10 + Math.random() * 20) + '%';
                friend.style.animationDelay = (index * 0.5) + 's';
                container.appendChild(friend);
            });
        }

        // 页面加载完成后添加动物朋友
        window.addEventListener('load', addAnimalFriends);
    </script>
</body>
</html>
